<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .div {
      /* display: flex; */
      /* align-items: center; */
      /* justify-content: center; */
      text-align: center;
      width: 200px;
      height: 200px;
      margin: 0 auto;
      background-color: rgb(216, 207, 207);
    }
  </style>
</head>

<body>

  <div id="app">
    <div @click="divClick" class="div">
      <!-- (1) .stop 当按钮被点击了之后，默认会有一个冒泡事件到div上，我们可以使用.stop阻止该事件冒泡 -->
      <button @click.stop="btnClick" class="btn">我是按钮</button>

      <!-- (2) .prevent 阻止默认事件的触发 -->
      <form action="baidu">
        <input type="submit" value="百度跳转" @click.prevent="submitClick">
      </form>

      <!-- (3) .enter 监听回车事件 -->
      <input class="input" type="text" @keyup.enter="keyUp">
      <input class="input" type="text" @keyup.a="keyUp">

      <!-- (4) .once 触发一次监听事件  -->
      <button @click.once="btnClick">我只能触发一次</button>
    </div>
  </div>

  <script src="../../js/vue.js"></script>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        message: 'hello'
      },

      methods: {
        btnClick() {
          console.log("按钮被点击了呀");
        },

        divClick() {
          console.log("div被点击了呀");
        },

        submitClick() {
          console.log("已监听到提交信息");
        },

        keyUp() {
          console.log("我听到了你的回车事件");
        }
      }
    })
  </script>
</body>

</html>